Imports System.IO
Imports System.Xml
Public Class frmConfiguracion
    '**************** Para poder Mover el Formulario sin titulo *****
    Private Const WM_SYSCOMMAND As Integer = &H112&
    Private Const MOUSE_MOVE As Integer = &HF012&
    '
    ' Declaraciones del API al estilo .NET
    <System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint:="ReleaseCapture")> _
    Private Shared Sub ReleaseCapture()
    End Sub
    <System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint:="SendMessage")> _
    Private Shared Sub SendMessage( _
            ByVal hWnd As System.IntPtr, ByVal wMsg As Integer, _
            ByVal wParam As Integer, ByVal lParam As Integer _
            )
    End Sub

    '****************//Para poder Mover el Formulario sin titulo *****
    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub frmConfiguracion_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Cargamos la configuracion
        txtPiloto.Text = cnfPiloto
        txtPassword.Text = cnfPassword
        txtIVAO.Text = cnfIVAO
        txtVATSIM.Text = cnfVATSIM
        txtmvsVAId.Text = cnfmvsVAId
        txtmvsUrlIVAO.Text = cnfmvsUrlIVAO
        txtmvsUrlMVS.Text = cnfmvsUrlMVS
        txtpathIvap.Text = cnfpathIvap
        txtSkin.Text = cnfSkin
        txtIdioma.Text = cnfIdioma
        If cnfIdioma = "es-ES" Then
            rbIdioma1.Checked = True
        Else
            rbIdioma2.Checked = True
        End If

        'Ponemos el formulario ajustado a la derecha y abajo
        'SetBounds(Screen.GetWorkingArea(Me).Width - Width, Screen.GetWorkingArea(Me).Height - Height, Width, Height)

    End Sub

    Private Sub txtPiloto_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPiloto.GotFocus
        txtPiloto.BackColor = Color.LightYellow
    End Sub

    Private Sub txtPiloto_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPiloto.LostFocus
        txtPiloto.BackColor = Color.White
    End Sub

    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        '****************** Leemos la Configuracion del XML ********
        Try
            Dim m_xmld As XmlDocument
            Dim m_nodelist As XmlNodeList

            'Cargamos el XML
            m_xmld = New XmlDocument()
            m_xmld.Load(str_XML)

            'Obtenemos la lista de los nodos "opcion"
            m_nodelist = m_xmld.SelectNodes("/opciones/opcion")

            'Capturamos los valores que nos interesan
            m_nodelist(0).ChildNodes.Item(0).InnerText = txtPiloto.Text
            m_nodelist(1).ChildNodes.Item(0).InnerText = txtPassword.Text
            m_nodelist(2).ChildNodes.Item(0).InnerText = txtIVAO.Text
            m_nodelist(3).ChildNodes.Item(0).InnerText = txtVATSIM.Text
            m_nodelist(4).ChildNodes.Item(0).InnerText = txtmvsVAId.Text
            m_nodelist(5).ChildNodes.Item(0).InnerText = txtmvsUrlIVAO.Text
            m_nodelist(6).ChildNodes.Item(0).InnerText = txtmvsUrlMVS.Text
            m_nodelist(7).ChildNodes.Item(0).InnerText = txtpathIvap.Text
            m_nodelist(8).ChildNodes.Item(0).InnerText = txtSkin.Text
            m_nodelist(9).ChildNodes.Item(0).InnerText = txtIdioma.Text

            cnfPiloto = m_nodelist(0).ChildNodes.Item(0).InnerText
            cnfPassword = m_nodelist(1).ChildNodes.Item(0).InnerText
            cnfIVAO = m_nodelist(2).ChildNodes.Item(0).InnerText
            cnfVATSIM = m_nodelist(3).ChildNodes.Item(0).InnerText
            cnfmvsVAId = m_nodelist(4).ChildNodes.Item(0).InnerText
            cnfmvsUrlIVAO = m_nodelist(5).ChildNodes.Item(0).InnerText
            cnfmvsUrlMVS = m_nodelist(6).ChildNodes.Item(0).InnerText
            cnfpathIvap = m_nodelist(7).ChildNodes.Item(0).InnerText
            cnfSkin = m_nodelist(8).ChildNodes.Item(0).InnerText
            cnfIdioma = m_nodelist(9).ChildNodes.Item(0).InnerText

            'Grabamos la configuracion
            m_xmld.Save(str_XML)

            Me.Close()

        Catch ex As Exception
            MessageBox.Show("Error al Grabar la Configuracion", My.Application.Info.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        '******************//Leemos la Configuracion del XML ********
    End Sub

    Private Sub btnPatth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPatth.Click
        'Mostramos La ventana para seleccionar el directorio
        FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
        FolderBrowserDialog1.ShowDialog()
        If Not (FolderBrowserDialog1.SelectedPath = "") Then
            txtpathIvap.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub btnSkin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSkin.Click

        Dim carpetas As Array
        Dim tmp As String
        'Mostramos La ventana para seleccionar el directorio
        FolderBrowserDialog1.Description = "Selecciona carpeta que contiene el ""skin"" que desees visualizar (por defecto: basico)"
        FolderBrowserDialog1.ShowNewFolderButton = False
        FolderBrowserDialog1.SelectedPath = My.Application.Info.DirectoryPath
        FolderBrowserDialog1.ShowDialog()
        'CESAR: seleccionamos el ultimo elemento del array que define la carpeta de los skin
        If (FolderBrowserDialog1.SelectedPath = "") Then
            txtSkin.Text = "basico"
        Else
            tmp = FolderBrowserDialog1.SelectedPath
            carpetas = Split(tmp, "\")
            txtSkin.Text = carpetas(carpetas.Length - 1).ToString
        End If

    End Sub

    Private Sub rbIdioma1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbIdioma1.CheckedChanged
        txtIdioma.Text = "es-ES"
    End Sub

    Private Sub rbIdioma2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbIdioma2.CheckedChanged
        txtIdioma.Text = "en-US"
    End Sub

    Private Sub frmConfiguracion_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Me.Handle, WM_SYSCOMMAND, MOUSE_MOVE, 0)
        End If
    End Sub

    Private Sub gbOtrosDatos_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gbOtrosDatos.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Me.Handle, WM_SYSCOMMAND, MOUSE_MOVE, 0)
        End If
    End Sub

    Private Sub gbDatosVA_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gbDatosVA.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Me.Handle, WM_SYSCOMMAND, MOUSE_MOVE, 0)
        End If
    End Sub

    Private Sub gbIdioma_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gbIdioma.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Me.Handle, WM_SYSCOMMAND, MOUSE_MOVE, 0)
        End If
    End Sub

    Private Sub gbDatosPiloto_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gbDatosPiloto.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Me.Handle, WM_SYSCOMMAND, MOUSE_MOVE, 0)
        End If
    End Sub

    Private Sub gbDatosVA_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gbDatosVA.Enter

    End Sub
End Class